package cluster

import (
	"krm-backend/config"
	"krm-backend/controllers"
	"krm-backend/utils/logs"

	"github.com/gin-gonic/gin"
)

type ResourceDetail struct {
	ResourceType string `json:"resourceType"`
	Total        int    `json:"total"`
}

func Detail(r *gin.Context) {
	logs.Debug(nil, "获取集群资源详情")
	clusterId := r.Query("clusterId")
	returnData := config.ReturnData{}
	var clusterDetail []ResourceDetail
	//统计 [resourceType]total
	for k, v := range controllers.ClusterStatistics[clusterId] {
		resourceDetail := ResourceDetail{
			ResourceType: k,
			Total:        v,
		}
		clusterDetail = append(clusterDetail, resourceDetail)
	}
	returnData.Status = 200
	returnData.Message = "查询成功"
	returnData.Data = make(map[string]interface{})
	returnData.Data["items"] = clusterDetail
	r.JSON(200, returnData)
}
